var site_url=localStorage.getItem("site_url");
/**
* created by Lee on 2019/1/9 12:07
*/

function pageStart(type){
	//当前页数
	var pageNo=$('#pageNo').val();
	//总页数
	var total_page=$('#total_page').val();
	//总条数
	var total_rows=$('#total_rows').val();
	var keyword=$('#keyword').val();
	// getData();
	//分页

	switch(type){
		case 1:
			break;	
		//参数设置
		case 711:
			getDataParam();
			break;
		//参数设置(出勤日设置)
		case 712:
			var time = new Date();
			var day = ("0" + time.getDate()).slice(-2);
			var month = "";
			var monthNum=time.getMonth() + 1;
			//小于10月，前面加0
			if(monthNum<10){
				month = ("0" + (time.getMonth() + 1)).slice(-2);
			}
			var today = time.getFullYear() + "-" + (month);
			$('#search_date_start').val(today);
			//本地保存的选择的部门的员工
			deparementStaffData();
			//部门的数据
			deparementData(1);
			systemSetData();
			break;	
		//参数设置(考勤规则)
		case 713:
			var groupId = localStorage.getItem("groupId");
			if(groupId!=null && groupId!=undefined && groupId!=""){
				laterulesData();
			}
			break;	
		//账号设置
		case 72:
			getDataAccount();
			break;		
		//轮播图设置
		case 73:
			getDataBanner();
			break;	
		//加班费用设置
		case 741:
			// localStorage.setItem("overtimeDepartId","");
			// deparementSetData(1);
			departSetData(1);
			// deparementData(2);
			break;	
		//请假费用设置
		case 742:
			localStorage.setItem("leaveDepartId","");
			deparementSetData(2);
			deparementData(3);
			break;	
		//排班设置
		case 75:
			scheduling();
			break;	
	}	
	/* $("#page").paging({
	    pageNo: parseInt(pageNo),
	    totalPage: parseInt(total_page),
	    totalSize: total_rows,
	    callback: function(num) {
	    }
	}) */
}
/* 全选按钮 */
function selectAll(type){
	// alert("ddd");
	var isCheck=$("#allCheck").is(':checked');  //获得全选复选框是否选中
	switch(type){
		case 1:
			
			break;
		case 2:
			$("input[name='staffId']").each(function() {  
				this.checked = isCheck; 
			}); 
			break;
		default:
			// alert(isCheck);
			$("input[type='checkbox']").each(function() {  
				this.checked = isCheck;
			});   
			break;
	}
	// $('input[name="dataId"]:checked').prop("checked", true);
}
//给参数设置页面赋值
function getDataParam(){
	var pageNo=$('#pageNo').val();
	var userToken=localStorage.getItem("userToken");
	
	var URL = site_url+"/attendancegroups?size=10&current="+pageNo;
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(data){
			$('#data').html("");
			var result = data.data.records;
	
			var html="";
			html+='<table cellpadding="0" cellspacing="0">';
			html+='<tr class="table-top">';
			html+='<td width="40%">考勤组名称</td><td width="40%">新增时间</td><td width="20%">操作</td></tr>';
			for (var i=0;i<result.length;i++) {
				if(i%2==0){
					html+='<tr class="item-white" onclick="dateEdit(1,\''+result[i].id+'\')">';
				}else{
					html+='<tr class="item-blue" onclick="dateEdit(1,\''+result[i].id+'\')">';
				}

				html+='<td>'+result[i].name+'</td>';
				html+='<td>'+result[i].createTime+'</td>';
				html+='<td>';
				html+='<a class="sys-check-btn" onclick="setOpera(1,\''+result[i].id+'\');">查看</a>/';
				html+='<a class="sys-update" onclick="setOpera(2,\''+result[i].id+'\');">修改</a>/';
				html+='<a class="sys-delete" onclick="setOpera(3,\''+result[i].id+'\');">删除</a>';
				html+='</td>';
				html+='</tr>';
						
			}
			if(result.length<=0){
				html+='<tr class="item-white">';
				html+='<td colspan="5" style="text-align:center;"><div>暂无数据</div></td>';
				html+='</tr>';
			}else{
				/* var pageNo=data.data.current;
				var total_page=data.data.pages;
						
				//分页
				$("#page").paging({
				    pageNo: parseInt(pageNo),
				    totalPage: parseInt(total_page),
				    callback: function(num) {
						$('#pageNo').val(num);
						getDataParam();
				    }
				}) */
				var pageNo=data.data.current;
				var total_page=data.data.pages;
				localStorage.setItem("total_page",total_page);
				//分页
				$("#page").paging({
				    pageNo: parseInt(pageNo),
				    totalPage: parseInt(total_page),
				    callback: function(num) {
						$('#pageNo').val(num);
						var total_page=localStorage.getItem("total_page");
						$("#page").paging({
						    pageNo: parseInt(num),
						    totalPage: parseInt(total_page)
						})
						getDataParam();
						$("#page").stopPagination({});
				    }
				})
			}
			html+='</table>';
			$('#data').html(html);

		}
	});
}
//给参数设置-出勤日设置页面赋值
function getDataAttendance(){
	$('#data-attendance').html("");
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth()+1;
	var totalDay = mGetDate(year,month);
	// alert(totalDay);
	var html="";
	html+='<table>';
	html+='<tr class="sys-table-top">';
	html+='<td width="20%">时间</td><td width="40%">打卡方式</td><td width="40%">当天班次</td></tr>';
	for (var i=1;i<=totalDay;i++) {
		html+='<tr class="sys-item-white">';
		html+='<td>'+month+'月'+i+'日</td>';
		html+='<td><select class="sys-select" id="ways'+i+'" style="margin-left: 0px;" onchange="attendanceCardWay('+i+');">';
		html+='<option id="0">请选择</option>';
		html+='<option id="1">分段打卡</option>';
		html+='<option id="2">休息</option></select></td>';
		html+='<td><div id="shifts'+i+'" style="display: block;">';
		html+='<input id="start_time'+i+'" type="time" class="sys-time"/>&nbsp;～&nbsp;<input id="end_time'+i+'" type="time" class="sys-time"/></div>';
		html+='<div id="rest'+i+'" class="rest-txt" style="display: none;">休息';
		html+='</div><td>';
		html+='</tr>';
	}

	html+='</table>';
	$('#data-attendance').html(html);
}
/* 根据选择的打卡方式显示对应的信息 */
function attendanceCardWay(id){
	var way=$("#ways"+id).val();
	if(way=="分段打卡"){
		$("#shifts"+id).show();
		$("#rest"+id).hide();
	}else if(way=="休息"){
		$("#rest"+id).show();
		$("#shifts"+id).hide();
	}
	//保存打卡方式
	localStorage.setItem("attendanceCardWay_"+id,way);
	// alert(way);
	
}
/*下一步 */
function sysNext(type){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		switch(type){
			/* 考勤设置基础信息 */
			case 1:
				
				break;
			/* 出勤日设置 */
			case 2:
				var date = new Date();
				var year = date.getFullYear();
				var month = date.getMonth()+1;
				var totalDay = mGetDate(year,month);
				var days="";
				for(var i=1;i<=totalDay;i++){
					var ways=localStorage.getItem("attendanceCardWay_"+i);
					
					if(ways!="分段打卡" && ways!="休息"){
						days+=i+",";
						// layer.alert("您"+i+"号的出勤日打卡方式还没有设置！"+ways, {icon: 5});
						// return;
					}
				}
				location.href="system_parameter_set4.html";
				break;
			/* 考勤核算规则设置 */
			case 3:
				location.href="system_parameter_set5.html";
				break;
			/* 选择适用部门 */
			case 4:
				location.href="system_parameter_set1.html";
				// layer.alert("完成！", {icon: 6});
				break;
			default:
				break;
		}
	});
}
/*新的参数设置下一步 */
function systemNext(type){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		var userToken=localStorage.getItem("userToken");
		switch(type){
			/* 考勤设置基础信息:添加 */
			case 1:
				//清空之前的数据
				localStorage.setItem("departId","");
				localStorage.setItem("amStart","");
				localStorage.setItem("amEnd","");
				localStorage.setItem("pmStart","");
				localStorage.setItem("pmEnd","");
				localStorage.setItem("replaceCardNum","");
				localStorage.setItem("leaveDuration","");
				localStorage.setItem("absenteeism","");
				localStorage.setItem("attendanceCycle","");
				//操作类 1：添加  2：修改
				localStorage.setItem("sysType","1");
				location.href="system_set2.html";
				break;
			/* 出勤日设置 */
			case 2:
				var searchMonth = $("#search_date_start").val();
				
				var morningStart = $("#am_start").val();
				var morningEnd = $("#am_end").val();
				var afternoonStart = $("#pm_start").val();
				var afternoonEnd = $("#pm_end").val();
				var year = searchMonth.split("-")[0];
				var month = searchMonth.split("-")[1];
				var totalDay = mGetDate(year,month);
				
				var id = localStorage.getItem("groupId")==null||localStorage.getItem("groupId")=="null"?'':localStorage.getItem("groupId");
				
				if(searchMonth==""){
					layer.alert("请选择选择月份", {icon: 5});
					return;
				}
				if (morningStart==null||morningEnd==null||afternoonStart==null||afternoonEnd==null||morningStart==""||morningEnd==""||afternoonStart==""||afternoonEnd=="") {
					layer.alert("请选择上班时间", {icon: 5});
					return;
				}
				var attendance = JSON.parse(localStorage.getItem("attendance"));
				if(attendance==""){
					layer.alert("没有人员数据不能提交！", {icon: 5});
					return;
				}
				var groupData = {
					name:searchMonth+"月-"+$("#select-dept-name").text()+"考勤组",
					deptId:localStorage.getItem("departId"),
					morningStart:morningStart,
					morningEnd:morningEnd,
					afternoonStart:afternoonStart,
					afternoonEnd:afternoonEnd,
					attendanceCycle:searchMonth,
					id:id
				}
				localStorage.setItem("groupData",JSON.stringify(groupData));
				var data = JSON.parse(localStorage.getItem("attendance"));
				for(var j =1;j<=data.length;j++){
					for (var i = 1; i <=totalDay; i++) {
						var d = $("#staff"+j+"_"+i).text();
						var day = "day"+i
						data[j-1][day] = d;
					}
				}
				localStorage.setItem("attendanceData",JSON.stringify(data));
				/* $.ajax({
					type:"POST",
					url:site_url+"/attendancegroups",
					ataType:"json",
					contentType:"application/json",
					headers:{'token':userToken},
					data: JSON.stringify(groupData),
					success:function(json){
						if(json.code==0){
							localStorage.setItem("groupId",json.data);
							var data = JSON.parse(localStorage.getItem("attendance"));
							for(var j =1;j<=data.length;j++){
								for (var i = 1; i <=totalDay; i++) {
									var d = $("#staff"+j+"_"+i).text();
									var day = "day"+i
									data[j-1][day] = d;
								}
								data[j-1].groupId=json.data;
							}
						
							$.ajax({
								type:"POST",
								url:site_url+"/personalattendances",
								ataType:"json",
								contentType:"application/json",
								headers:{'token':userToken},
								data: JSON.stringify(data),
								success:function(obj){
									if(obj.code==0){
										location.href="system_set3.html";
									}else{
										layer.alert(obj.msg, {icon: 5});
									}
								}
							});
							
						}else{
							layer.alert("保存失败！", {icon: 5});
						}
					}
				}); */
				location.href="system_set3.html";
				break;
			/* 考勤核算规则设置 */
			case 3:
				// setParamCommit();
				//location.href="system_set1.html";
				var lateRuleModel = $("#late_type").val();//迟到计算方式
				var lateRuleMoney = $("#late_money").val();//迟到金额
				var lateRuleMoney1 = $("#late_money1").val();//迟到人性化
				var leaveEarlyModel = $("#leave_early_type").val();//早退计算方式
				var leaveEarlyMoney = $("#leave_early_money").val();//早退金额
				var leaveEarlyMoney1 = $("#leave_early_money1").val();//早退人性化
				var absenteeism = $("#absenteeism").val();//旷工工资
				var replaceCardNum = $("#replace_card_num").val();//补卡次数
				var leaveDuration = $("#leave_duration").val();//周期
				var groupId = localStorage.getItem("groupId");
				if(lateRuleMoney=="" || lateRuleMoney<0){
					layer.alert("迟到金额不能为空或小于0！", {icon: 5});
					return;
				}
				if(lateRuleMoney1=="" || lateRuleMoney1<0){
					layer.alert("迟到人性化设置不能为空或小于0！", {icon: 5});
					return;
				}
				if(leaveEarlyMoney=="" || leaveEarlyMoney<0){
					layer.alert("早退金额不能为空或小于0！", {icon: 5});
					return;
				}
				if(leaveEarlyMoney1=="" || leaveEarlyMoney1<0){
					layer.alert("早退人性化设置不能为空或小于0！", {icon: 5});
					return;
				}
				if(absenteeism=="" || absenteeism<0){
					layer.alert("旷工工资不能为空或小于0！", {icon: 5});
					return;
				}
				if(replaceCardNum=="" || replaceCardNum<0){
					layer.alert("补卡次数不能为空或小于0！", {icon: 5});
					return;
				}
				if(leaveDuration=="" || leaveDuration<0){
					layer.alert("超过天数不能为空或小于0！", {icon: 5});
					return;
				}
				var dataRule = {
					groupId:groupId,
					lateRuleModel:lateRuleModel,
					lateRuleMoney:lateRuleMoney,
					laterRuleExempt:lateRuleMoney1,
					leaveEarlyModel:leaveEarlyModel,
					leaveEarlyMoney:leaveEarlyMoney,
					leaveEarlyExempt:leaveEarlyMoney1,
					absenteeism:absenteeism,
					replaceCardNum:replaceCardNum,
					leaveDuration:leaveDuration,
				}
				
				var userToken=localStorage.getItem("userToken");
				var groupData=JSON.parse(localStorage.getItem("groupData"));
				$.ajax({
					type:"POST",
					url:site_url+"/attendancegroups",
					ataType:"json",
					contentType:"application/json",
					headers:{'token':userToken},
					data: JSON.stringify(groupData),
					success:function(json){
						if(json.code==0){
							localStorage.setItem("groupId",json.data);
							var attendanceData=JSON.parse(localStorage.getItem("attendanceData"));
							for(var j =1;j<=attendanceData.length;j++){
								attendanceData[j-1].groupId=json.data;
							}
						
							$.ajax({
								type:"POST",
								url:site_url+"/personalattendances",
								ataType:"json",
								contentType:"application/json",
								headers:{'token':userToken},
								data: JSON.stringify(attendanceData),
								success:function(obj){
									if(obj.code==0){
										dataRule.groupId=localStorage.getItem("groupId");
										// localStorage.setItem("dataRule",JSON.stringify(dataRule));
										setParamCommit(dataRule);
									}else{
										layer.alert(obj.msg, {icon: 5});
									}
								}
							});
							
						}else{
							layer.alert("保存失败！", {icon: 5});
						}
					}
				}); 
				
				
				break;
			default:
				break;
		}
	});
}
/* 提交参数设置 */
function setParamCommit(data){
	// var data=JSON.parse(localStorage.getItem("dataRule"));
	var userToken=localStorage.getItem("userToken");
	$.ajax({
		type:"POST",
		url:site_url+"/attendancegroups/rule",
		ataType:"json",
		contentType:"application/json",
		headers:{'token':userToken},
		data: JSON.stringify(data),
		success:function(obj){
			if(obj.code==0){
				localStorage.setItem("attendanceCycle","")
				location.href="system_set1.html";
			}else{
				layer.alert(obj.msg, {icon: 5});
			}
		}
	});
}
/* 获取一个月的天数 */
function mGetDate(year, month){
    var d = new Date(year, month, 0);
    return d.getDate();
}
/* 头像更换 */
function headChange(type,file){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		if (!file.files || !file.files[0]){
		    return;
		}else{
		    var name=file.files[0].name;
		    var extName = name.substring(name.lastIndexOf(".")+1).toLowerCase();
		    if(extName=="jpg" || extName=="png" || extName=="jpeg"){
		    }else{
				layer.alert("图片格式不正确！", {icon: 5});
		        return;
		    }
		}
		var windowURL = window.URL || window.webkitURL;
		var fileObj = file;
		var dataURL;
		dataURL = windowURL.createObjectURL(fileObj.files[0]);
		switch(type){
			/* 头像选择 */
			case 1:
				$("#headImg").attr('src', dataURL);
				$("#headImgEdit").attr('src', dataURL);
				
				var img = $("#headFile")[0].files[0];
				
				var reader = new FileReader();
				if (img) {
			 	    var imgUrlBase64 = reader.readAsDataURL(img);
        			reader.onload = function (e) {
        			
    					var userToken=localStorage.getItem("userToken");
						var URL=site_url+"/users/token";
						var user="";
						$.ajax({
						    type: 'GET',
						    url: URL,
						    dataType:"json",
							headers:{'token':userToken},
						    data: "",
						    success: function (json) {
								userInfo=json.data;
								var head_img = reader.result;
								var data={
									id:userInfo.id,
									avatar:head_img
								}
								var userToken=localStorage.getItem("userToken");
								$.ajax({
									type:"PUT",
									url:site_url+"/users/avatar",
									headers:{'token':userToken},
						        	contentType: 'application/json; charset=utf-8',
									data:JSON.stringify(data),
									success: function (json) {
										if (json.data) {
											layer.alert("修改成功！", {icon: 6});
										}
								    }
								});
						    }
					   })
        			}
				}
				
				break;
			/* 轮播图添加选择 */
			case 2:
				$("#bannerImg").attr('src', dataURL);
				$("#banner-bg").css("display","none");
				$("#choose-pic-txt").css("display","block");
				$("#bannerImg").css("display","block");
				break;
			/* 轮播图修改选择 */
			case 3:
				$("#bannerEditImg").attr('src', dataURL);
				
				break;
		}
		// layer.alert("地址！"+dataURL, {icon: 5});
		
	});
}
/* 提交 */
function accountSubmit(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		/* 编辑页面显示 */
		$("#account_info").show();
		/* 详情隐藏 */
		$("#account_edit").hide();
		var name=$("#name").val();
		var job=$("#job_edit").val();
		var department=$("#deptId").val();
		var sex=$("#sex").val();
		
		var userToken=localStorage.getItem("userToken");
		var userInfo = JSON.parse(localStorage.getItem("userInfo"));
		var data={
			id:userInfo.id,
			deptId:department,
			name:name,
			job:job,
			sex:sex
		};
		var URL=site_url+"/users/web"
		$.ajax({
		    type: 'PUT',
		    url: URL,
		    dataType:"json",
			contentType:"application/json",
			headers:{'token':userToken},
			data: JSON.stringify(data),
		    success: function (json) {
		    	getDataAccount();
		    	layer.alert("提交成功！", {icon: 6});
		    }
		})
		
	});
}
/* 编辑 */
function accountEditShow(){
	var userToken=localStorage.getItem("userToken");
	var URL=site_url+"/users/token";
	$.ajax({
		    type: 'GET',
		    url: URL,
		    dataType:"json",
			headers:{'token':userToken},
		    data: "",
		    success: function (json) {
				userInfo=json.data;
				console.log(userInfo.job)
				$("#headImgEdit").attr("src",userInfo.avatar);
				$("#name").val(userInfo.name);
				$("#job_edit").val(userInfo.job);
				$("#department").val(userInfo.deptName);
				$("#deptId").val(userInfo.deptId);
				$("#sex").val(userInfo.sex=="男"?1:2);
			}
	 });
	/* 编辑页面显示 */
	$("#account_edit").show();
	/* 详情隐藏 */
	$("#account_info").hide();
}
/* 取消 */
function accountCancel(){
	/* 编辑页面显示 */
	$("#account_info").show();
	/* 详情隐藏 */
	$("#account_edit").hide();
}
/* 修改 */
function accountEdit(type){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		var title="";
		var userToken = localStorage.getItem("userToken");
		var userInfo = JSON.parse(localStorage.getItem("userInfo"));
		switch(type){
			//密码
			case 1:
				password=$("#pwd_head_edit").val();
				$.ajax({
					type:"get",
					url:site_url+"/users/password?userId="+userInfo.id+"&newPassword="+password,
					dataType:"json",
					headers:{'token':userToken},
					success:function(data){
						if (data.code == 0) {
							layer.alert("修改成功",{icon: 6})
						}else{
							layer.alert("修改失败",{icon: 5})
						}
					}
				});
				break;
			//家乡
			case 2:
				address=$("#address").val();
				$.ajax({
					type:"PUT",
					url:site_url+"/users/web",
					dataType:"json",
					contentType: 'application/json; charset=utf-8',
					headers:{'token':userToken},
					data:JSON.stringify({
						id:userInfo.id,
						hometown:address
					}),
					success:function(data){
						if (data.code == 0) {
							layer.alert("修改成功",{icon: 6})
						}else{
							layer.alert("修改失败",{icon: 5})
						}
					}
				});
				break;
			//现居
			case 3:
				currentResidence=$("#current_residence").val();
				$.ajax({
					type:"PUT",
					url:site_url+"/users/web",
					dataType:"json",
					contentType: 'application/json; charset=utf-8',
					headers:{'token':userToken},
					data:JSON.stringify({
						id:userInfo.id,
						currentResidence:currentResidence
					}),
					success:function(data){
						if (data.code == 0) {
							layer.alert("修改成功",{icon: 6})
						}else{
							layer.alert("修改失败",{icon: 5})
						}
					}
				});
				break;
			//工龄
			case 4:
				worksYear=$("#working_years").val();
				$.ajax({
					type:"PUT",
					url:site_url+"/users/web",
					dataType:"json",
					contentType: 'application/json; charset=utf-8',
					headers:{'token':userToken},
					data:JSON.stringify({
						id:userInfo.id,
						worksYear:worksYear
					}),
					success:function(data){
						if (data.code == 0) {
							layer.alert("修改成功",{icon: 6})
						}else{
							layer.alert("修改失败",{icon: 5})
						}
					}
				});
				break;
		}
//		layer.alert("修改成功！"+title, {icon: 6});
	});
}
/* 账户赋值 */
function getDataAccount(){

		var userToken=localStorage.getItem("userToken");
		var URL=site_url+"/users/token";
		var user="";
		$.ajax({
		    type: 'GET',
		    url: URL,
		    dataType:"json",
			headers:{'token':userToken},
		    data: "",
		    success: function (json) {
				userInfo=json.data;
				// alert(userInfo.hometown);
				$("#headImg").attr("src",userInfo.avatar);
				$("#userName_head").text(userInfo.name);
				$("#job_head").text(userInfo.job);
				$("#deptName_head").text(userInfo.deptName);
				$("#sex_head").text(userInfo.sex);
				$("#phone_head").text(userInfo.phone);
//				$("#pwd").val(userInfo.password)
				$("#address").val(userInfo.hometown);
				$("#current_residence").val(userInfo.currentResidence);
				$("#working_years").val(userInfo.worksYear);
				$("#sex_head").val(userInfo.sex);
				$("#phone_head").text(userInfo.phone);
				
				$.ajax({
					type:"get",
					url:site_url+"/users/dept?deptId="+userInfo.deptId,
					dataType:"json",
					headers:{'token':userToken},
					success:function(data){
						$('#data_user').html("");
						var userList = data.data.records;
						var html="";
						html+='<table>';
						html+='<tr class="table-top">';
						html+='<td width="6%"><input id="allCheck" type="checkbox" value="0" onchange="selectAll()"></td><td width="10%">序号</td>';
						html+='<td width="10%">姓名</td><td width="10%">岗位</td><td width="14%">电话</td><td width="10%">登录次数</td>';
						html+='<td width="20%">最后登录时间</td><td width="10%">状态</td><td width="10%">操作</td></tr>';
						
						for (var i=0;i<userList.length;i++) {
							
							var state =userList[i].valid;
							if(state){
								/* if(i%2==0){
									html+='<tr class="item-white">';
								}else{
									html+='<tr class="item-blue">';
								} */
								html+='<tr class="item-white">';
								html+='<td><input type="checkbox" name="dataId" value="'+userList[i].id+'"></td>';
								html+='<td>'+(i+1)+'</td>';	
								html+='<td>'+userList[i].name+'</td>';
								html+='<td>'+userList[i].job+'</td>';
								html+='<td>'+userList[i].phone+'</td>';
								html+='<td>0</td>';
								html+='<td>无</td>';
								html+='<td></td>';
								html+='<td>';
								html+='<img src="img/edit_icon.png" onclick="showUser(2,\''+userList[i].id+'\');"/>';
								html+='<img style="margin-left: 10px;" src="img/delete_icon.png" onclick="dateDelete(1,\''+userList[i].id+'\');"/>';
								html+='</td>';
								html+='</tr>';
							}
							
						}
						html+='</table>';
						$('#data_user').html(html);
					}
				});
		    }
		});
	
}

/* 获取用户信息 */
function getUserInfo(){

		var userToken=localStorage.getItem("userToken");
		var URL=site_url+"/users/token";
		var user="";
		$.ajax({
		    type: 'GET',
		    url: URL,
		    dataType:"json",
			headers:{'token':userToken},
		    success: function (json) {
				user=json.data;
		    }
		});
		return user;
}
/* 显示用户界面（1：新增 2：编辑） */
function showUser(type,id){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		switch(type){
			/* 新增账号 */
			case 1:
				var job = getPositionType();
				$("#position").html("");
				for(var i=0;i<job.length;i++){
					$("#position").append( $('<option value="'+job[i].value+'">'+job[i].label+'</option>'));
				}
				$("#addDiv").show();
				break;
			/* 编辑账号 */
			case 2:
				$("#userId").val(id);
				
				var userToken=localStorage.getItem("userToken");
				$.ajax({
					type:"GET",
					url:site_url+"/users?id="+id,
					ataType:"json",
					headers:{'token':userToken},
					success:function(data){
						if(data.data!=null){
							var job = getPositionType();
							$("#position_edit").html("");
							for(var i=0;i<job.length;i++){
								if(data.data.job==job[i].label){
									$("#position_edit").append( $('<option value="'+job[i].value+'" selected = "selected" >'+job[i].label+'</option>'));
								}else{
									$("#position_edit").append( $('<option value="'+job[i].value+'">'+job[i].label+'</option>'));
								}
							}
							$("#userId").val(id);
							$("#userNum_edit").val(id);
							$("#pwd_edit").val(data.data.pwd);
							$("#confirmPwd_edit").val(data.data.pwd);
							$("#userName_edit").val(data.data.name);
							$("#contact_edit").val(data.data.phone);
							// $("#position_edit").val(data.data.job);
							$("#status_edit").val("启用");
						}
						
						$("#editDiv").show();
					}
				});
				
				
				break;
			default:
				break;
		}
	    // layer.alert("查看！"+id, {icon: 6});
	});	
}
/* 用户界面的关闭按钮 */
function closePop(type){
	switch(type){
		/* 新增账号 */
		case 1:
			$("#addDiv").hide();
			break;
		/* 编辑账号 */
		case 2:
			$("#editDiv").hide();
			break;
		/* 轮播图添加 */
		case 3:
			$("#bannerImg").attr('src', "img/banner-default.png");
			$("#banner-bg").css("display","block");
			$("#choose-pic-txt").css("display","none");
			$("#bannerImg").css("display","none");
			$("#bannerDiv").hide();
			break;
		/* 轮播图编辑 */
		case 4:
			$("#bannerEditDiv").hide();
			break;
		/* 选择部门 */
		case 5:
			$("#sys-right-data").html("");
			$("#departDiv").hide();
			// deparementData(1);
			// deparementStaffData();
			break;
		/* 查看考勤方案 */
		case 6:
			$("#checkInfo").hide();
			break;
		default:
			break;
	}	
}
/* 用户界面的保存按钮 */
function btnSave(type){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
	    var userInfo = JSON.parse(localStorage.getItem("userInfo"));
	    var userToken=localStorage.getItem("userToken");
		switch(type){
			/* 新增账号 */
			case 1:
				var userNum=$("#userNum").val();
				var pwd=$("#pwd").val();
				var confirmPwd=$("#confirmPwd").val();
				var userName=$("#userName").val();
				var contact=$("#contact").val();
				var position=$("#position").val();
				var status=$("#status").val();
				
				if (pwd=="") {
					layer.alert("密码不能为空！",{icon: 5});
					return;
				}
				if (confirmPwd=="") {
					layer.alert("确认密码不能为空！",{icon: 5});
					return;
				}
				if (pwd!=confirmPwd) {
					layer.alert("两次密码不一致！请重新输入",{icon: 5});
					return;
				}
				if (userName=="") {
					layer.alert("用户名不能为空！",{icon: 5});
					return;
				}
				if (contact=="") {
					layer.alert("联系电话不能为空！",{icon: 5});
					return;
				}
				var data = {
					empNum:userNum,
					password:pwd,
					name:userName,
					phone:contact,
					job:position,
					vaild:status=="启用"?true:false,
					deptId:userInfo.deptId,
					roleId:4
				}
				
				$.ajax({
					type:"POST",
					url:site_url+"/users/add",
					ataType:"json",
					contentType:"application/json",
					headers:{'token':userToken},
					data: JSON.stringify(data),
					success:function(data){
						if(data.code==0){
							// layer.alert("保存成功！", {icon: 6});
							location.reload();
						}else{
							layer.alert("保存失败！", {icon: 5});
						}
					}
				});
				
				break;
			/* 编辑账号 */
			case 2:
				var id=$("#userId").val();
				var userNum_edit=$("#userNum_edit").val();
				var pwd_edit=$("#pwd_edit").val();
				var confirmPwd_edit=$("#confirmPwd_edit").val();
				var userName_edit=$("#userName_edit").val();
				var contact_edit=$("#contact_edit").val();
				var position_edit=$("#position_edit").val();
				var status_edit=$("#status_edit").val();
				
				if (pwd_edit!=confirmPwd_edit) {
					layer.alert("两次密码不一致！请重新输入",{icon: 5});
					return;
				}
				if (userName_edit=="") {
					layer.alert("用户名不能为空！",{icon: 5});
					return;
				}
				if (contact_edit=="") {
					layer.alert("联系电话不能为空！",{icon: 5});
					return;
				}
				
				var data = {
					id:id,
					empNum:userNum_edit,
					password:pwd_edit,
					name:userName_edit,
					phone:contact_edit,
					job:position_edit,
					vaild:status_edit=="启用"?true:false,
					deptId:userInfo.deptId,
					roleId:4
				}
				
				$.ajax({
					type:"PUT",
					url:site_url+"/users/web",
					ataType:"json",
					contentType:"application/json",
					headers:{'token':userToken},
					data: JSON.stringify(data),
					success:function(data){
						if(data.code==0){
							// layer.alert("编辑成功！", {icon: 6});
							location.reload();
						}else{
							layer.alert(data.msg, {icon: 5});
						}
					}
				});
				break;
			default:
				break;
		}	
	});	
}
/* 批量删除按钮 */
function batchDelete(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		var chk_value = [];
        $('input[name="dataId"]:checked').each(function () {
            chk_value.push($(this).val());
			   this.checked = "checked"; 
        });
		var URL = site_url+"/users/list/"+chk_value;
		var userToken=localStorage.getItem("userToken");
		$.ajax({
			type:"DELETE",
			url:URL,
			headers:{'token':userToken},
			dataType:"json",
			async:false,
			success:function(data){
				if(data.code==0){
					layer.alert("删除成功！", {icon: 6});
					location.reload();
				}else{
					layer.alert(data.msg, {icon: 6});
				}
				
			}
		});
	});	
}
/* 删除 */
function dateDelete(type,id){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		switch(type){
			/* 账号信息 */
			case 1:
				deleteUserById(id);
				break;
			/* 补卡说明 */
			case 2:
				break;
			/* 选择部门的删除 */
			case 3:
				localStorage.setItem("departId",null);
				$("#sys-depart-data").html("");
				setStaffNull();
				break;
				
			default:
				break;
		}
	    // layer.alert("删除！"+id, {icon: 6});
	});
}
/* 删除管理账号模块的用户信息 */
function deleteUserById(id){
	layui.use(['element', 'layer'], function() {
	var URL = site_url+"/users?id="+id;
	var userToken=localStorage.getItem("userToken");
		$.ajax({
			type:"DELETE",
			url:URL,
			headers:{'token':userToken},
			dataType:"json",
			async:false,
			success:function(data){
				if(data.code==0){
					layer.alert("删除成功！", {icon: 6});
					location.reload();
				}else{
					layer.alert(data.msg, {icon: 6});
				}
			}
		});
	})
}
/* 权限 */
function authorityCheck(type){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		switch(type){
			/* 只读 */
			case 1:
				// alert(res);
				$("#authorityRead").prop('checked', true);
				$("#authorityAll").prop('checked', false);
				$("#authorityRead_edit").prop('checked', true);
				$("#authorityAll_edit").prop('checked', false);
				break;
			/* 全部 */
			case 2:
				$("#authorityAll").prop('checked', true);
				$("#authorityRead").prop('checked', false);
				$("#authorityAll_edit").prop('checked', true);
				$("#authorityRead_edit").prop('checked', false);
				break;
			default:
				break;
		}
	});
}
/* 部门箭头切换 */
function arrowChange(id){
	var name=document.getElementById("depart-arrow"+id).className;
	// var name=$("#depart-arrow").className;
	//打开下拉列表信息
	if(name=="sys-depart-item-down"){
		document.getElementById("depart-arrow"+id).className="sys-depart-item-up";
		//数据区域显示
		$("#depart-data-staff"+id).show();
		$("#departId"+id).css("height","340px");
		
	}else{
		document.getElementById("depart-arrow"+id).className="sys-depart-item-down";
		//数据区域隐藏
		$("#depart-data-staff"+id).hide();
		$("#departId"+id).css("height","auto");
	}
	// alert(name);
}
/* 未选中部门的时候赋值空的表格 */
function setStaffNull(){
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth()+1;
	var totalDay = mGetDate(year,month);
	var html='';
	html+='<table cellpadding="0" cellspacing="0">';
	html+='<tr class="sys-table-top-staff">';
	html+='<td colspan="'+(totalDay+7)+'" style="text-align: center;">考勤表</td>';
	html+='</tr>';
	html+='<tr class="sys-table-top-staff">';
	html+='<td rowspan="2" colspan="3" class="sys-table-top-staff">姓名</td>';
	html+='<td rowspan="2" colspan="4" class="sys-table-top-staff">电话</td>';
	html+='<td colspan="'+totalDay+'">排班日期</td>';
	html+='</tr>';
	
	html+='<tr class="sys-table-top-staff">';
	for(var i=1;i<=totalDay;i++){
		html+='<td>'+i+'</td>';
	}
	html+='</tr>';
	html+='<tr class="sys-item-white-staff">';
	html+='<td colspan="3"></td>';
	html+='<td colspan="4"></td>';
	for(var i=1;i<=totalDay;i++){
		html+='<td></td>';
	}
	html+='</tr>';
	$("#data_schedul").html(html);

}
/* 选择部门员工的数据 */
function deparementStaffData(){
	var departId=localStorage.getItem("departId");
	if(departId==null || departId=="null" || departId==""){
		$("#am_start").val("");
		$("#am_end").val("");
		$("#pm_start").val("");
		$("#pm_end").val("");
		localStorage.setItem("amStart","");
		localStorage.setItem("amEnd","");
		localStorage.setItem("pmStart","");
		localStorage.setItem("pmEnd","");
		
		setStaffNull();
		return;
	}
	var URL = site_url+"/depts?id="+departId;
	var userToken=localStorage.getItem("userToken");
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(data){
			$("#sys-depart-data").html("");
			var html='';
			html+='<div class="sys-depart-item" id="departId'+data.data.id+'">';
			html+='<div class="sys-depart-item-top">';
			html+='<img class="sys-depart-item-img" src="img/sys_depart_icon.png" />';
			html+='<label id="select-dept-name" >'+data.data.name+'</label>';
			html+='<img class="sys-depart-item-close" src="img/close_icon.png" onclick="dateDelete(3,'+data.data.id+');"/>';
			html+='</div>';
			html+='</div>';
			
			$("#sys-depart-data").html(html);
			epartDataSave();
			//-----------------------------------部门成员列表--------------------------------------------------------
		}
	})
}

function epartDataSave(){
	
	var departId=localStorage.getItem("departId");
	var searchMonth="";
	/* if(searchMonth==""){
		
		searchMonth = localStorage.getItem("attendanceCycle");
		if(searchMonth==""){
			var time = new Date();
			var day = ("0" + time.getDate()).slice(-2);
			var month = "";
			var monthNum=time.getMonth() + 1;
			//小于10月，前面加0
			if(monthNum<10){
				month = ("0" + (time.getMonth() + 1)).slice(-2);
			}
			var today = time.getFullYear() + "-" + (month);
			$('#search_date_start').val(today);
			searchMonth=$("#search_date_start").val();
		}
	} */
	var type=localStorage.getItem("sysType");
	//添加
	if(type==1){
		searchMonth = $("#search_date_start").val();
	}
	//修改(第一次进入页面)
	else if(type==2){
		searchMonth = localStorage.getItem("attendanceCycle");
		localStorage.setItem("sysType","3");
	}
	//修改(数据随日期改变)
	else if(type==3){
		searchMonth = $("#search_date_start").val();
		if(searchMonth==""){
			searchMonth = localStorage.getItem("attendanceCycle");
		}
	}
	if(departId!="" && searchMonth!=""){
		staffData(departId,searchMonth);
	}
	// alert(departId+","+searchMonth);
	
}

/* 员工显示的表格 */
function staffData(departId,searchMonth){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		// var date = new Date();
		var year = searchMonth.split("-")[0];
		var month = searchMonth.split("-")[1];
		var totalDay = mGetDate(year,month);
		$("#data_schedul").html("");
		var html='';
		html+='<table cellpadding="0" cellspacing="0" style="width:90%;min-width:1000px;">';
		html+='<tr class="sys-table-top-staff">';
		html+='<td colspan="'+(totalDay+7)+'" style="text-align: center;">'+month+'月份考勤</td>';
		html+='</tr>';
		html+='<tr class="sys-table-top-staff">';
		html+='<td rowspan="2" colspan="3" class="sys-table-top-staff">姓名</td>';
		html+='<td rowspan="2" colspan="4" class="sys-table-top-staff">电话</td>';
		html+='<td colspan="'+totalDay+'">排班日期</td>';
		html+='</tr>';
		
		html+='<tr class="sys-table-top-staff">';
		for(var i=1;i<=totalDay;i++){
			html+='<td style="height:30px">'+i+'</td>';
		}
		html+='</tr>';
		html+='</table>';
		var URL = site_url+"/attendancegroups/dept?deptId="+parseInt(departId)+"&attendanceCycle="+searchMonth;
		var userToken=localStorage.getItem("userToken");
		$.ajax({
			type:"get",
			url:URL,
			headers:{'token':userToken},
			success:function(data){
				if(data.code==0){
					var data=data.data;
					localStorage.setItem("attendance",JSON.stringify(data));
					if (data.length>0) {
						localStorage.setItem("groupId",data[0].groupId);
					}
					// html+='<tr>';
					html+='<div style="overflow-y: scroll;overflow-x: hidden;height: 410px;border:1px solid #fff;width:95%;min-width:1050px;">';
					html+='<table style="margin-top:-2px;">';
					for(var j=1;j<=data.length;j++){
						html+='<tr class="sys-item-white-staff">';
						html+='<td colspan="3">'+data[j-1].userName+'</td>';
						html+='<td colspan="4">'+data[j-1].phone+'</td>';
						for(var i=1;i<=totalDay;i++){
							var day = "day"+i;
							var text = data[j-1][day]==null?"√":data[j-1][day]
							html+='<td><div id="staff'+j+'_'+i+'" onclick="setRest('+j+','+i+');">'+text+'</div></td>';
						}
						html+='</tr>';
					}
					html+='</table>';
					html+='</div>';
					
				}else{
					layer.alert(data.msg, {icon: 5});
				}
				
				$("#data_schedul").html(html);
			}
		})
	});
	
	
}
/* 部门的数据 type 1:参数设置  2：加班费用设置  3：请假费用设置*/
function deparementData(type){
	$("#sys-left-depart").html("");
	var html='';
	
	/* if(type==1){
		var URL = site_url+"/depts/all";
		var userToken=localStorage.getItem("userToken");
		$.ajax({
			type:"get",
			url:URL,
			headers:{'token':userToken},
			success:function(data){
				for(var i=0;i<data.length;i++){
					html+='<div class="sys-left-depart-item">';
					html+='<input style="margin-top:10px;" id="departCheck'+data[i].id+'" type="checkbox" name="departId" value="'+data[i].id+'" onclick="departCheckBox('+type+','+data[i].id+');">';
					html+='<div class="sys-depart-txt" title="'+data[i].name+'" id="departName'+data[i].id+'">'+data[i].name+'</div>';
					html+='</div>';
				}
				$("#sys-left-depart").html(html);
			}
		});
	} */
	getDataDepartment(type);
	$('#files').tree({
		expanded: 'li:first'
	});
	
}
/* 部门选择 */
function departCheckBox(type,id){
	//只能选择一个
	/* if(type==1){
		$("input[name='departId']").each(function() {  
			this.checked = false;
		}); 
		$("#departCheck"+id).prop("checked",true);
			
	} */
	var name=$("#departName"+id).html();
	//保存部门id
	localStorage.setItem("departId",id);
	localStorage.setItem("departName",name);
	//加班费用部门id保存
	localStorage.setItem("overtimeDepartId",id);
	localStorage.setItem("overtimeDepartName",name);
	//请假部门id保存
	localStorage.setItem("leaveDepartId",id);
	localStorage.setItem("leaveDepartName",name);
	
	// alert(isCheck);
}
/* 项目部选择 */
function projectCheckBox(type,id){
	//只能选择一个
	var name=$("#subject"+id).html();
	// alert(name);
	//保存部门id
	localStorage.setItem("departId",id);
	localStorage.setItem("departName",name);
	//加班费用部门id保存
	localStorage.setItem("overtimeDepartId",id);
	localStorage.setItem("overtimeDepartName",name);
	//请假部门id保存
	localStorage.setItem("leaveDepartId",id);
	localStorage.setItem("leaveDepartName",name);

	// alert(isCheck);
	
}
/* 选择部门的员工后保存数据，如果是之前保存过的部门，则替换之前的数据，如果是新部门，则数据加一条 */
function departDataSave1(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		var staff_value = [];
		var staff_str="";
		$('input[name="staffId"]:checked').each(function () {
		    staff_value.push($(this).val());
			staff_str+=$(this).val()+'-';
		});
		// var staffArray = staff_value.split(",");
		var departId=localStorage.getItem("departId");
		// alert(departId);
		var staffArray=[];
		if(staff_value==""){
			layer.alert("您没有选择员工！", {icon: 5});
		}else{
			var depart={
				"departId":departId,
				"staff":staff_value,
			
			};
			// alert(staff_str);
			//之前保存的部门id
			var departIds=localStorage.getItem("departIds");
			//之前保存的部门选择的员工id
			var staffIds = JSON.parse(localStorage.getItem("departStaffData"));
			// alert("之前保存的数据："+staffIds);
			if(departIds!=null){
				var id = departIds.split(",");
				// alert("部门数组个数："+id.length);
				var index=-1;
				for(var i=1;i<=id.length;i++){
					if(departId==i){
						// alert("之前保存过的部门下标："+i);
						index=i-1;
					}
				}
				//如果不包含该部门的数据，就加上
				// if(departIds.indexOf(departId) == -1){
				if(index<0){
					// alert("不包含");
					departIds+=','+departId;
					localStorage.setItem("departIds",departIds); 
					//在数组后面加上一条数据
					staffIds.push(staff_str);
				}
				//如果已经有该部门的数据，就替换选择的员工数据
				else{
					// alert("替换的数据："+staffIds[index]);
					//替换之前的数据
					staffIds[index]=staff_str;
				}
				localStorage.setItem("departStaffData",JSON.stringify(staffIds)); 
			}else{
				// alert("null=="+departIds);
				//保存部门id
				localStorage.setItem("departIds",departId);
				//保存部门对应的员工id
				staffArray[0]=staff_str;
				localStorage.setItem("departStaffData",JSON.stringify(staffArray));
			}
			// localStorage.setItem("departData",depart);
		}
		
		$("#departDiv").hide();
		// layer.alert("保存成功！", {icon: 6});
		// alert(array[0]);
		
	});
}
/* 只保存部门数据 */
function departDataSave(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		// var departId=localStorage.getItem("departId");
		// //之前保存的部门id
		// var departIds=localStorage.getItem("departIds");
		// if(departIds!=null){
		// 	var id = departIds.split(",");
		// 	//如果不包含该部门的数据，就加上
		// 	if(departIds.indexOf(departId) == -1){
		// 		// alert("不包含");
		// 		departIds+=','+departId;
		// 		localStorage.setItem("departIds",departIds); 
		// 	}
		// }else{
		// 	//保存部门id
		// 	localStorage.setItem("departIds",departId);
		// }
		// // alert(departIds);
		// 
		// staffArray=[];
		// staffDateArray=[];
		// //员工id
		// localStorage.setItem("departStaffData",JSON.stringify(staffArray));
		// //员工休息的日期id
		// localStorage.setItem("staffRestData",JSON.stringify(staffDateArray));
		var departId=localStorage.getItem("departId");
		if(departId==null || departId==""){
			layer.alert("您还没有选择部门！", {icon: 6});
			return;
		}
		// $("#am_start").val("13:34");
		deparementStaffData();
		$("#departDiv").hide();
		
	});
}
/* 参数设置的操作 */
function setOpera(type,id){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		switch(type){
			//查看
			case 1:
				// alert(departId);
				checkStaffData(id);
				$("#checkInfo").show();
				break;
			//修改
			case 2:
				localStorage.setItem("sysType","2");
				var attendanceGroup = getAttendanceGroupById(id);
			
				localStorage.setItem("departId",attendanceGroup.deptId);
				//考勤组标题
				localStorage.setItem("attendanceName",attendanceGroup.name);
				//保存时间
				localStorage.setItem("amStart",attendanceGroup.morningStart);
				localStorage.setItem("amEnd",attendanceGroup.morningEnd);
				localStorage.setItem("pmStart",attendanceGroup.afternoonStart);
				localStorage.setItem("pmEnd",attendanceGroup.afternoonEnd);
				
				localStorage.setItem("attendanceCycle",attendanceGroup.attendanceCycle);
				localStorage.setItem("replaceCardNum",attendanceGroup.replaceCardNum);
				localStorage.setItem("leaveDuration",attendanceGroup.leaveDuration);
				localStorage.setItem("absenteeism",attendanceGroup.absenteeism);
				// alert(attendanceGroup.morningStart);
				departDataSave();
				location.href = "system_set2.html";
				break;
			//删除
			case 3:
				layer.confirm('您确定删除吗？', { icon: 3, title: '提示',shade:0 }, function (index) {
					var URL = site_url+"/attendancegroups?id="+id;
					var userToken=localStorage.getItem("userToken");
					$.ajax({
						type:"DELETE",
						url:URL,
						headers:{'token':userToken},
						success:function(data){
							if (data.code==0) {
								layer.alert("删除成功！", {icon: 6});
								location.reload();
							}else{
								layer.alert(data.msg, {icon: 5});
							}
						},
					})
					layer.close(index);
				});
				// 
				break;
		}
	});
	
}
/* 查看部门员工考勤表 */
function checkStaffData(id){

	$("#data_schedul").html("");
	
	var URL = site_url+"/personalattendances/groupId?groupId="+id;
	var userToken=localStorage.getItem("userToken");
	$.ajax({
		type:"get",
		url:URL,
		headers:{'token':userToken},
		success:function(data){
			if (data.length>0) {
				var attendanceGroup = getAttendanceGroupById(id);
				var date = new Date(attendanceGroup.attendanceCycle.split("-")[0],attendanceGroup.attendanceCycle.split("-")[1]-1,1);
				var year = date.getFullYear();
				var month = date.getMonth()+1;
				var totalDay = mGetDate(year,month);
				var html='';
				html+='<table cellpadding="0" cellspacing="0">';
				html+='<tr class="sys-table-top-staff">';
				html+='<td colspan="'+(totalDay+7)+'" style="text-align: center;">'+month+'月份考勤</td>';
				html+='</tr>';
				html+='<tr class="sys-table-top-staff">';
				html+='<td rowspan="2" colspan="3" class="sys-table-top-staff">姓名</td>';
				html+='<td rowspan="2" colspan="4" class="sys-table-top-staff">电话</td>';
				html+='<td colspan="'+totalDay+'">排班日期</td>';
				html+='</tr>';
				
				html+='<tr class="sys-table-top-staff">';
				
				for(var i=1;i<=totalDay;i++){
					html+='<td>'+i+'</td>';
				}
				html+='</tr>';
				for(var j=1;j<=data.length;j++){
					html+='<tr class="sys-item-white-staff">';
					html+='<td colspan="3">'+data[j-1].userName+'</td>';
					html+='<td colspan="4">'+data[j-1].phone+'</td>';
					for(var i=1;i<=totalDay;i++){
						var day = "day"+i;
						var text = data[j-1][day]==null?"√":data[j-1][day];
						if(i%7==0){
							html+='<td><div id="staff'+j+'_'+i+'" style="color:#263d7c;">'+text+'</div></td>';
						}else{
							html+='<td><div id="staff'+j+'_'+i+'">'+text+'</div></td>';
						}
					}
					html+='</tr>';
				}
				
				$("#data_schedul").html(html);
			}
		},
	})
}

function getAttendanceGroupById(id){
	var attendanceGroup={};
	var URL = site_url+"/attendancegroups/"+id;
	var userToken=localStorage.getItem("userToken");
	$.ajax({
		type:"get",
		url:URL,
		async:false,
		headers:{'token':userToken},
		success:function(data){
			attendanceGroup = data.data;
		},
	})
	
	return attendanceGroup;
}

/* 设置员工休息 */
function setRest(staffId,dateId){
	 var txt = $("#staff"+staffId+"_"+dateId).text();
	 if(txt=="休"){
		$("#staff"+staffId+"_"+dateId).text('√');
	 }
	 if(txt!="休"){
	 	$("#staff"+staffId+"_"+dateId).text("休");
	 }
	 // var date_str="";
	 // date_str+=dateId+',';
	 // var departId=localStorage.getItem("departId");
	 // //员工id
	 // var staffIds = JSON.parse(localStorage.getItem("departStaffData"));
	 // //员工休息的日期id
	 // var staffRests = JSON.parse(localStorage.getItem("staffRestData"));
	 // 
	 // if(staffIds!=null){
	 // 	// var id = staffIds.split(",");
	 // 	var index=-1;
		// //通过用户id 获取用户在数组中的坐标
	 // 	for(var i=1;i<=staffIds.length;i++){
	 // 		if(staffId==i){
	 // 			index=i-1;
	 // 		}
	 // 	}
		// var date_str = staffRests[index];
		// // alert("之前保存的数据date_str："+date_str);
		// //根据小标获取该用户保存的休息日期
		// var dataArray = [];
		// dataArray = date_str.split(",");
		// var date_index=-1;
		// for(var j=0;j<dataArray.length-1;j++){
		// 	if(dateId==dataArray[j]){
		// 		date_index=j;
		// 	}
		// }
		// //休息操作时
		// if(txt=="休"){
		// 	
		// 	//之前保存过,就删除该数据
		// 	// dataArray.remove(date_index);
		// 	dataArray[date_index]="";
		// 	// dataArray.splice(date_index,1);
		// 	date_str="";
		// 	for(var j=1;j<=dataArray.length;j++){
		// 		if(dataArray[j-1]!=""){
		// 			date_str+=dataArray[j-1]+",";
		// 		}
		// 	}
		// 	// alert("删除下标："+date_index+"=删除数据后="+date_str);
		// }
		// //取消休息操作时
		// else{
		// 	//之前没有保存过,就追加到数据后面
		// 	date_str+=dateId+",";
		// }
	 // 	staffRests[index]=date_str;
		// // alert(date_str);
		// localStorage.setItem("staffRestData",JSON.stringify(staffRests));
	 // }
	 
	/* var val = $(this).val();
	alert("val:"+val); */
}
//--------------------------------------轮播图-----------------------------------------
/* 轮播图数据 */
function getDataBanner(){
	var html='';
	var URL=site_url+"/banners/dept";
	// alert(URL);
	
	var userToken=localStorage.getItem("userToken");
	var userInfo = JSON.parse(localStorage.getItem("userInfo"));
	// alert(userInfo.deptId);
	var data={
		userId:userInfo.id,
		deptId:userInfo.deptId
	};
	
	$.ajax({
	    type: 'GET',
	    url: URL,
	    dataType:"json",
		headers:{'token':userToken},
		// contentType:"application/json",
	    data: data,
	    success: function (json) {
			var data=json.data;
			for(var i=0;i<data.length;i++){
				html+='<div class="banner-item-data">';
				html+='<img id="bannerImg'+data[i].id+'" class="banner-item-img" src="'+data[i].url+'"/>';
				html+='<button class="banner-item-edit" onclick="bannerClick(1,'+data[i].id+');">修改</button>';
				html+='<button class="banner-item-delete" onclick="bannerClick(2,'+data[i].id+');">删除</button>';
				html+='</div>';
			}
			$("#banner-list").html(html);
	    }
	}); 
	
}
/* 打开选中图片的弹出框 */
function showPic(type,id){
	//添加
	if(type==1){
		$("#bannerDiv").show();
	}
	//修改
	else if(type==2){
		$("#bannerId").val(id);
		$("#bannerEditDiv").show();
	}
	//选择适用部门(参数设置)
	else if(type==3){
		deparementData(1);
		$("#departDiv").show();
	}
	//选择适用部门(加班费用设置)
	else if(type==4){
		deparementData(2);
		$("#departDiv").show();
	}
	//选择适用部门(请假费用设置)
	else if(type==5){
		deparementData(3);
		$("#departDiv").show();
	}
}
/* 选择图片后页面显示该图片 type 1:添加  2：修改*/
function bannerSave(type){
	var reader = new FileReader();
    var AllowImgFileSize = 5100000; //上传图片最大值(单位字节)
	var file = "";
	if(type==1){
		file = $("#bannerFile")[0].files[0];
	}else{
		file = $("#bannerEditFile")[0].files[0];
	}
    var imgUrlBase64;
    if (file) {
        //将文件以Data URL形式读入页面  
        imgUrlBase64 = reader.readAsDataURL(file);
        reader.onload = function (e) {
			//var ImgFileSize = reader.result.substring(reader.result.indexOf(",") + 1).length;//截取base64码部分
			if (AllowImgFileSize != 0 && AllowImgFileSize < reader.result.length) {
				alert( '上传失败，请上传不大于5M的图片！');
				return;
			}else{
				switch(type){
					//添加
					case 1:
						//执行上传操作
						// alert(reader.result);
						var URL=site_url+"/banners";
						// alert(URL);
						var userToken=localStorage.getItem("userToken");
						var userInfo = JSON.parse(localStorage.getItem("userInfo"));
						console.log(reader.result)
						// alert(URL);
						var data={
							userId:userInfo.id,
							deptId:userInfo.deptId,
							url:reader.result
						};
						$.ajax({
						    type: 'POST',
						    url: URL,
						    dataType:"json",
							contentType:"application/json",
							headers:{'token':userToken},
							data: JSON.stringify(data),
						    success: function (json) {
								// layer.alert("json="+json, {icon: 6,shade:0});
								var res=json.code;
								switch(res){
									case 0:
										layer.alert("添加成功！", {icon: 6,shade:0});
										location.reload();
										break;
									case 1:
										layer.alert("添加失败！", {icon: 5,shade:0});
										break;
								}
						    }
						});
						break;
					//修改
					case 2:
						//执行上传操作
						var URL=site_url+"/banners";
						var bannerId=$("#bannerId").val(); 
						// alert(bannerId);
						var userToken=localStorage.getItem("userToken");
						var userInfo = JSON.parse(localStorage.getItem("userInfo"));
						var data={
							id:bannerId,
							userId:userInfo.id,
							deptId:userInfo.deptId,
							url:reader.result
						};
						$.ajax({
						    type: 'PUT',
						    url: URL,
						    dataType:"json",
							contentType:"application/json",
							headers:{'token':userToken},
							data: JSON.stringify(data),
						    success: function (json) {
								layer.alert("json="+json.code, {icon: 6,shade:0});
								var res=json.code;
								switch(res){
									case 0:
										layer.alert("编辑成功！", {icon: 6,shade:0});
										getDataBanner();
										break;
									case 1:
										layer.alert("编辑失败！", {icon: 5,shade:0});
										break;
								}
						    }
						});
					break;
				}
				
			}
        }
    }
	var windowURL = window.URL || window.webkitURL;
	// alert(dataURL);
	switch(type){
		//添加
		case 1:
			var fileObj =  $("#bannerFile")[0];
			var dataURL;
			dataURL = windowURL.createObjectURL(fileObj.files[0]);
			// alert(dataURL);
			var html='<div class="banner-item-data">';
			html+='<img id="bannerImg7" class="banner-item-img" src="'+dataURL+'"/>';
			html+='<button class="banner-item-edit" onclick="bannerClick(1,7);">修改</button>';
			html+='<button class="banner-item-delete" onclick="bannerClick(2,7);">删除</button>';
			html+='</div>';
			$("#banner-list").append(html);
			break;
		//修改
		case 2:
			/* var fileObj =  $("#bannerEditFile")[0];
			var dataURL;
			dataURL = windowURL.createObjectURL(fileObj.files[0]);
			var id=$("#bannerId").val();
			// alert(id);
			$("#bannerImg"+id).attr('src',dataURL); */
			
			break;
	}
}
/* 图片点击后的操作 */
function bannerClick(type,id){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		switch(type){
			//修改
			case 1:
				var imgSrc=$("#bannerImg"+id).attr('src');
				// alert("====="+id);
				$("#bannerEditImg").attr('src', imgSrc);
				showPic(2,id);
				break;
			//删除
			case 2:
				var URL=site_url+"/banners?id="+id;
				// alert(id);
				var data={
					id:id
				};
				layer.confirm('确定删除该数据吗？', { icon: 3, title: '提示',shade:0 }, function (index) {
					$.ajax({
						type: 'DELETE',
						url: URL,
						dataType:"json",
						// contentType:"application/json",
						data: "",
						success: function (json) {
							var res=json.code;
							// alert(json);
							if(res==0){
								layer.alert("删除成功！", {icon: 6,shade:0});
								location.reload();
							}else if(res==1){
								layer.alert("删除失败！", {icon: 5,shade:0});
							}
						}
					});
					layer.close(index);
				});
				break;
		}
		
	});	
}
//--------------------------------------轮播图结束-----------------------------------------
//--------------------------------------费用设置开始-----------------------------------------
/* 费用数据 */
function deparementSetData(type){
	var departIds="";
	var name="";
	var num=0;
	//加班费用设置
	if(type==1){
		
		
		departIds=localStorage.getItem("overtimeDepartId");
		name=localStorage.getItem("overtimeDepartName");
		num=1;
		if(departIds==null || departIds=="null" || departIds==""){
			// $("#sys-depart-data").html("您还没有选择部门");
			setStaffNull();
			return;
		}
		var userToken = localStorage.getItem("userToken");
		var year=localStorage.getItem("calenderYear");
		var month=localStorage.getItem("calenderMonth");
		if(month<10){
			month="0"+month;
		}
		$.ajax({
			url:site_url+"/deptovertimefees/dept/"+departIds,
			dataType:'json',
			type:"GET",
			headers:{'token':userToken},
			success:function(data){
				$("#overtime").val(data.data.unitPrice);
				if(data.data.id!=null){
					$("#overtimeId").val(data.data.id);
				}else{
					$("#overtimeId").val("");
				}
				
				localStorage.setItem("overtimeId",data.data.id);
				localStorage.setItem("overtime",data.data.unitPrice);
				$.ajax({
					url:site_url+"/deptfeemultiples?deptId="+departIds+"&overtimeDate="+(year+"-"+month),
					dataType:'json',
					type:"GET",
					headers:{'token':userToken},
					success:function(data){
						var data=data.data;
						var chooseDays1=[];
						var chooseDays2=[];
						var chooseDays3=[];
						var multiple=0;
						var date="";
						//获取日(最后一个"-"到最后一个字符之间)
						var day="";
						for(var i=0;i<data.length;i++){
							multiple=data[i].multiple;
							date=data[i].overtimeDate;
							//获取日(最后一个"-"到最后一个字符之间)
							day=date.substring(date.lastIndexOf('-')+1,date.length);
							// alert("multiple="+multiple+",day="+day);
							if(multiple==1){
								chooseDays1.push(day);
							}else if(multiple==2){
								chooseDays2.push(day);
							}else if(multiple==3){
								chooseDays3.push(day);
							}
						}
						if(data.length>0){
							if(chooseDays1!=""){
								localStorage.setItem("chooseDays1",JSON.stringify(chooseDays1));
							}else{
								localStorage.setItem("chooseDays1","");
							}
							if(chooseDays2!=""){
								localStorage.setItem("chooseDays2",JSON.stringify(chooseDays2));
							}else{
								localStorage.setItem("chooseDays2","");
							}
							if(chooseDays3!=""){
								localStorage.setItem("chooseDays3",JSON.stringify(chooseDays3));
							}else{
								localStorage.setItem("chooseDays3","");
							}
							// $().calender();
						}else{
							localStorage.setItem("chooseDays1","");
							localStorage.setItem("chooseDays2","");
							localStorage.setItem("chooseDays3","");
						}
						location.reload();
						// console.log(data)
					}
				})
			}
		})
	}
	//请假费用设置
	else if(type==2){
		departIds=localStorage.getItem("leaveDepartId");
		name=localStorage.getItem("leaveDepartName");
		num=1;
	}else{
		departIds=localStorage.getItem("departId");
		name=localStorage.getItem("departName");
		num=1;
	}
	if(departIds==null || departIds=="null" || departIds==""){
		// $("#sys-depart-data").html("您还没有选择部门");
		setStaffNull();
		return;
	}
	
	var departNum = departIds.split(",");
	
	// alert("部门个数："+departNum.length);
	$("#sys-depart-data").html("");
	var html='';
	html+='<div class="sys-depart-item" id="departId'+departIds+'">';
	html+='<div class="sys-depart-item-top">';
	html+='<img class="sys-depart-item-img" src="img/sys_depart_icon.png" />';
	html+='<label>'+name+'</label>';
	// html+='<img class="sys-depart-item-close" src="img/close_icon.png" onclick="dateDelete(3,'+(i+1)+');"/>';
	html+='</div>';
	html+='</div>';
	// if(type==2){
		// html+='<div class="sys-depart-item" id="departId'+departIds+'">';
		// html+='<div class="sys-depart-item-top">';
		// html+='<img class="sys-depart-item-img" src="img/sys_depart_icon.png" />';
		// html+='<label>'+name+'</label>';
		// // html+='<img class="sys-depart-item-close" src="img/close_icon.png" onclick="dateDelete(3,'+(i+1)+');"/>';
		// html+='</div>';
		// html+='</div>';
	// }else{
	// 
	// }
	
	$("#sys-depart-data").html(html);
}
function departSetData(){
	var departIds="";
	var name="";
	var num=0;
	departIds=localStorage.getItem("overtimeDepartId");
	name=localStorage.getItem("departName");
	num=1;
	if(departIds==null || departIds=="null" || departIds==""){
		// $("#sys-depart-data").html("您还没有选择部门");
		setStaffNull();
		return;
	}
	
	var departNum = departIds.split(",");
	
	// alert("部门个数："+departNum.length);
	$("#sys-depart-data").html("");
	var html='';
	html+='<div class="sys-depart-item" id="departId'+departIds+'">';
	html+='<div class="sys-depart-item-top">';
	html+='<img class="sys-depart-item-img" src="img/sys_depart_icon.png" />';
	html+='<label>'+name+'</label>';
	// html+='<img class="sys-depart-item-close" src="img/close_icon.png" onclick="dateDelete(3,'+(i+1)+');"/>';
	html+='</div>';
	html+='</div>';
	
	$("#sys-depart-data").html(html);
	var overtime=localStorage.getItem("overtime");
	$("#overtime").val(overtime);
}
/* 请假费用设置的保存 */
function leaveAddSave(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		  //选择的第一种方式
		  var isCheck1=$("#leaveType1").is(':checked'); 
		  var isCheck2=$("#leaveType2").is(':checked'); 
		  var leaveTime=$('#leaveTime').val();  //请假时间
		  var halfTime=$('#halfTime').val();    //超过几小时半天
		  // var allTime=$('#allTime').val(); 	    //超过几小时一天
		  var ruleType=-1;
		  var departIds=localStorage.getItem("leaveDepartId");
		  if(departIds==null || departIds==""){
		  		layer.alert("请选择部门！", {icon: 5});
		  		return;
		  }
		  if(isCheck1){
			  ruleType=0;
		  }
		  if(isCheck2){
		  	ruleType=1;
		  }
		  if(!isCheck1 && !isCheck2){
			  layer.alert("请选择一种请假扣款规则！", {icon: 5});
			  return;
		  }
		  //选择的扣款方式为第一种时，才进行是否为空判断
		  if(isCheck1){
			  if(leaveTime=="" || leaveTime<=0){
			  		layer.alert("请假时间不能为空或负数！", {icon: 5});
			  		return;
			  }
			  if(halfTime=="" || halfTime<=0){
			  		layer.alert("超过几小时半天不能为空或负数！", {icon: 5});
			  		return;
			  }
			  /* if(allTime=="" || allTime<=0){
			  		layer.alert("超过几小时一天不能为空或负数！", {icon: 5});
			  		return;
			  } */
		  }else{
			  leaveTime=0;
			  halfTime=0;
		  }
		  var id=$('#leaveId').val();
		  var data={
		  	"id":id,
			"deptId":departIds,
		  	"rule":ruleType,
		  	"nonDeductionTime":leaveTime,
			"calcHalfDay":halfTime
			// "calcADay":allTime
		  };
		  var userToken=localStorage.getItem("userToken");
		  URL = site_url+"/leavefeesets";
		  $.ajax({
		  	type:"POST",
		  	url:URL,
		  	headers:{'token':userToken},
		  	contentType:"application/json",
		  	data: JSON.stringify(data),
		  	success:function(data){
		  		if (data.code == 0){
		  			layer.alert("请假费用设置成功！", {icon: 6});
					/* localStorage.setItem("leaveDepartId","");
					$("#leaveType1").prop("checked", false);
					$("#leaveType2").prop("checked", false);
					$("#leaveId").val("");
					$("#leaveTime").val("");
					$("#halfTime").val("");
					$("#allTime").val(""); */
					// location.reload();
		  		}
		  	}
		  })
	});	
}
/* 请假费用设置只能选择一个 */
function leaveCheckBox(id){
	// alert(isCheck);
	$("input[name='leaveId']").each(function() {  
	    this.checked = false;
	}); 
	$("#leaveType"+id).prop("checked",true);

}
/* 费用设置部门数据 */
function costDepartDataSave(type){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		/* var departId="";
		$('input[name="departId"]:checked').each(function () {
			departId+=$(this).val()+',';
		}); */
		var userToken=localStorage.getItem("userToken");
		// alert(userToken);
		//保存加班费用设置
		if(type==1){
			// localStorage.setItem("overtimeDepartId",departId);
			var id=localStorage.getItem("overtimeDepartId");
			if(id=="" || id==null ){
				layer.alert("请选择部门！", {icon: 6});
				return;
			}
			deparementSetData(type);
		}
		//保存请假费用设置
		else if(type==2){
			var id=localStorage.getItem("leaveDepartId");
			if(id=="" || id==null ){
				layer.alert("请选择部门！", {icon: 6});
				return;
			}
			var URL = site_url+"/leavefeesets";
			var data={
				"deptId":id
			};
			$.ajax({
				type:"GET",
				url:URL,
				headers:{'token':userToken},
				contentType: 'charset=utf-8',
				data:data,
				success:function(data){
					var data=data.data;
					// alert(data.nonDeductionTime);
					if(data!=null){
						var rule=data.rule;
						if(rule==0){
							 $("#leaveType1").prop("checked", true);
							 $("#leaveType2").prop("checked", false);
						}else if(rule==1){
							 $("#leaveType2").prop("checked", true);
							 $("#leaveType1").prop("checked", false);
						}
						
						$("#leaveId").val(data.id);
						$("#leaveTime").val(data.nonDeductionTime);
						$("#halfTime").val(data.calcHalfDay);
						// $("#allTime").val(data.calcADay);
					}
					deparementSetData(type);
				}
			})
		}
		
		$("#departDiv").hide();
	});
}
/* 设置费用 */
function costSet(type){
	// alert(type);
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		$("#costSetModal").hide();
		layer.alert("您设置了"+type+"倍工资！", {icon: 6});
		run(0);
	});
	
}
/* 获取分级的部门数据 */
function getDataDepartment(type){
	$('#sys-left-depart').html("");
	var dept = getByParentId(-1);
	var html="";
	//alert(dept.length);
	html+='<ul id="files">';
	for (var k = 0; k < dept.length; k++) {
		var deptChildren = getByParentId(dept[k].id);
		html+='<li><a href="javascript:void(0);"><img src="img/file_icon.png"/>&nbsp;<label id="subjectName'+dept[k].id+'">'+dept[k].name+'</label></a>';								
		html+='<ul id="subject">';
		for (var i = 0; i < deptChildren.length; i++) {
			var deptChildrens = getByParentId(deptChildren[i].id);
			html+='<li id="sub'+deptChildren[i].id+'"><a href="#" onclick="projectCheckBox('+type+',\''+deptChildren[i].id+'\');">&nbsp;';
			html+='<label class="depart-left-txt" id="subject'+deptChildren[i].id+'" title="'+deptChildren[i].name+'" >'+deptChildren[i].name+'</label>';
			html+='</a>';
			html+='<ul id="departmentUl'+deptChildren[i].id+'">';
			for(var j=0;j<deptChildrens.length;j++){
				html+='<li id="depart'+deptChildrens[j].parentId+'"><a href="#" onclick="departCheckBox('+type+',\''+deptChildrens[j].id+'\');">';
				html+='<label class="depart-left-txt" id="departName'+deptChildrens[j].id+'" title="'+deptChildrens[j].name+'">'+deptChildrens[j].name+'</label>';
				html+='</a></li>';
			}
			html+='</ul>';
			html+='</li>';
		}
		html+='</ul>';
		html+='</li>';
	}
	html+='</ul>';
	
	
	$('#sys-left-depart').html(html);
	
	//左侧数据树状显示
	$('#files').tree({
		expanded: 'li:first'
	});
}
function getByParentId(id){
	
	var URL = site_url+"/depts/parent?id="+id;
	var userToken=localStorage.getItem("userToken");
	var depts;
	$.ajax({
		type:'GET',
		url:URL,
		headers:{'token':userToken},
		dataType:"json",
		async:false,
		success: function (json) {
	      depts = json.data;
		  // alert(depts);
	    }
	});

	return depts;
}
//--------------------------------------费用设置结束-----------------------------------------
/* 加班费用设置的保存 */
function overtimeAddSave(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		  var overtime=$('#overtime').val();  //加班时间
		  var departIds=localStorage.getItem("overtimeDepartId");
		  // alert(departIds);
		  if(departIds==null || departIds==""){
		  		layer.alert("请选择部门！", {icon: 5});
		  		return;
		  }
		 if(overtime=="" || overtime<=0){
		 		layer.alert("加班时间不能为空或负数！", {icon: 5});
		 		return;
		 }
		  
		 layer.alert("加班费用设置成功！", {icon: 6});
	});	
}
/* 修改进入页面的赋值 */
function systemSetData(){
	layui.use(['element', 'layer'], function() {
	    var layer = layui.layer;
		var am_start=localStorage.getItem("amStart");
		var am_end=localStorage.getItem("amEnd");
		var pm_start=localStorage.getItem("pmStart");
		var pm_end=localStorage.getItem("pmEnd");
		if(am_start!=null && am_start!=""){
				// alert("====="+am_start);
			$("#am_start").val(am_start);
		}else{
			$("#am_start").val("");
		}
		if(am_end!=null && am_end!=""){
			$("#am_end").val(am_end);
		}else{
			$("#am_end").val("");
		}
		if(pm_start!=null && pm_start!=""){
			$("#pm_start").val(pm_start);
		}else{
			$("#pm_start").val("");
		}
		if(pm_end!=null && pm_end!=""){
			$("#pm_end").val(pm_end);
		}else{
			$("#pm_end").val("");
		}
		var attendanceCycle=localStorage.getItem("attendanceCycle");
		if(attendanceCycle!=null && attendanceCycle!=""){
			$("#search_date_start").val(attendanceCycle);
		}else{
			var time = new Date();
			var day = ("0" + time.getDate()).slice(-2);
			var month = "";
			var monthNum=time.getMonth() + 1;
			//小于10月，前面加0
			if(monthNum<10){
				month = ("0" + (time.getMonth() + 1)).slice(-2);
			}
			var today = time.getFullYear() + "-" + (month);
			
			$('#search_date_start').val(today);
			// $("#search_date_start").val("");
		}
		//考勤规则赋值
	/* 	var replaceCardNum=localStorage.getItem("replaceCardNum");
		if(replaceCardNum!=null && replaceCardNum!=""){
			$("#search_date_start").val(replaceCardNum);
		}else{
			$("#search_date_start").val("");
		}
		var leaveDuration=localStorage.getItem("leaveDuration");
		if(leaveDuration!=null && leaveDuration!=""){
			$("#search_date_start").val(leaveDuration);
		}else{
			$("#search_date_start").val("");
		}
		var absenteeism=localStorage.getItem("absenteeism");
		if(absenteeism!=null && absenteeism!=""){
			$("#search_date_start").val(absenteeism);
		}else{
			$("#search_date_start").val("");
		} */

	});
}

/* 根据选变化文字 */
function sysClick(type){
	//迟到
	if(type==1){
		var nameId=$("#late_type").val();
		if(nameId==0){
			$("#lateTxt").text("元/次");
			$("#lateTxt1").text("次，不扣款");
		}else{
			$("#lateTxt").text("元/分钟");
			$("#lateTxt1").text("分钟，不扣款");
		}
		$("#late_type1").val(nameId);
	}
	//早退
	if(type==2){
		var nameId=$("#leave_early_type").val();
		if(nameId==0){
			$("#earlyTxt").text("元/次");
			$("#earlyTxt1").text("次，不扣款");
		}else{
			$("#earlyTxt").text("元/分钟");
			$("#earlyTxt1").text("分钟，不扣款");
		}
		$("#leave_early_type1").val(nameId);
	}
}
/*查询职位*/
function getPositionType () {
	$("#position_staff").html("");
	$("#position_staff_edit").html("");
	var result = [];
	var userToken = localStorage.getItem("userToken");
	$.ajax({
		url:site_url+"/dicts/job",
		dataType:'json',
		async:false,
		headers:{'token':userToken},
		success:function(data){
			result = data.data;
		}
	})
	return result;
}
/* 考勤规则 */
function laterulesData() {
	var userToken = localStorage.getItem("userToken");
	var groupId = localStorage.getItem("groupId");
	//迟到
	$.ajax({
		url:site_url+"/laterules/groupId?groupId="+groupId,
		dataType:'json',
		async:false,
		headers:{'token':userToken},
		success:function(data){
			var data=data.data;
			$("#late_type").val(data.model);
			$("#late_money").val(data.money);//迟到金额
			$("#late_type1").val(data.model);
			$("#late_money1").val(data.exempt);//迟到人性化
			if(data.model==0){
				$("#lateTxt").text("元/次");
				$("#lateTxt1").text("次，不扣款");
			}else{
				$("#lateTxt").text("元/分钟");
				$("#lateTxt1").text("分钟，不扣款");
			}
		}
	})
	//早退
	$.ajax({
		url:site_url+"/leaveearlyrules/groupId?groupId="+groupId,
		dataType:'json',
		async:false,
		headers:{'token':userToken},
		success:function(data){
			var data=data.data;
			$("#leave_early_type").val(data.model);//早退计算方式
			$("#leave_early_money").val(data.money);//早退金额
			$("#leave_early_type1").val(data.model);
			$("#leave_early_money1").val(data.exempt);//早退人性化
			if(data.model==0){
				$("#earlyTxt").text("元/次");
				$("#earlyTxt1").text("次，不扣款");
			}else{
				$("#earlyTxt").text("元/分钟");
				$("#earlyTxt1").text("分钟，不扣款");
			}
		}
	})

	var replaceCardNum=localStorage.getItem("replaceCardNum");
	if(replaceCardNum!=null && replaceCardNum!=""){
		$("#replace_card_num").val(replaceCardNum);
	}else{
		$("#replace_card_num").val("");
	}
	var leaveDuration=localStorage.getItem("leaveDuration");
	if(leaveDuration!=null && leaveDuration!=""){
		$("#leave_duration").val(leaveDuration);
	}else{
		$("#leave_duration").val("");
	}
	var absenteeism=localStorage.getItem("absenteeism");
	if(absenteeism!=null && absenteeism!=""){
		$("#absenteeism").val(absenteeism);
	}else{
		$("#absenteeism").val("");
	}	
}
/* 排班数据的修改弹出框 */
function schedulShow (type) {
	schedulChange(type);
	$("#editDiv").show();
}
/* 下拉框的改变事件 */
function schedulChange(type){
	if(type==""){
		type=$("#type").val();
	}else{
		$("#type").val(type);
	}
	if(type==1){
		$("#schedul1").show();
		$("#schedul2").hide();
		$("#schedul3").hide();
		$("#schedulTxt").html("(上12休24)");
	}
	if(type==2 || type==5){
		$("#schedul2").show();
		$("#schedul1").hide();
		$("#schedul3").hide();
	}
	if(type==3){
		$("#schedul1").show();
		$("#schedul2").hide();
		$("#schedul3").hide();
		$("#schedulTxt").html("(白班)");
	}
	if(type==4){
		$("#schedul3").show();
		$("#schedul1").hide();
		$("#schedul2").hide();
	}
	/* switch(type){
		case 1:
			$("#schedul1").show();
			$("#schedul2").hide();
			$("#schedul3").hide();
			$("#schedulTxt").val("(上12休24)");
			break;
		case 2:
			$("#schedul2").show();
			$("#schedul1").hide();
			$("#schedul3").hide();
			break;
		case 3:
			$("#schedul1").show();
			$("#schedul2").hide();
			$("#schedul3").hide();
			$("#schedulTxt").val("(白班)");
			break;
		case 4:
			$("#schedul3").show();
			$("#schedul1").hide();
			$("#schedul2").hide();
			break;
		case 5:
			$("#schedul2").show();
			$("#schedul1").hide();
			$("#schedul3").hide();
			break;
	} */
}
/* 排班数据 */
function scheduling(){
	
}
/* 排班修改 */
function schedulEdit(){
	type=$("#type").val();
	var amStartTime="";
	var amEndTime="";
	var pmStartTime="";
	var pmEndtime="";
	if(type==1 || type==3){
		amStartTime=$("#am_start1").val();
		pmEndtime=$("#pm_end1").val();
	}
	if(type==2 || type==5){
		amStartTime=$("#am_start2").val();
		amEndTime=$("#am_end2").val();
		pmStartTime=$("#pm_start2").val();
		pmEndtime=$("#pm_end2").val();
	}
	if(type==4){
		amStartTime=$("#pm_start3").val();
		pmEndtime=$("#am_end3").val();
	}
	
}
